package org.luxor.eshop.account.controller;

import lombok.extern.slf4j.Slf4j;
import org.luxor.commons.core.web.controller.BaseRestController;
import org.luxor.commons.core.web.data.R;
import org.luxor.eshop.account.entity.AccountEntity;
import org.luxor.eshop.account.entity.dto.PaymentReqDto;
import org.luxor.eshop.account.entity.dto.ReceiptReqDto;
import org.luxor.eshop.account.service.impl.AccountServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 账户服务
 *
 * @author Mr.Yan  @date 2019/9/19
 */
@Slf4j
@RestController
@RequestMapping("/account")
public class AccountController extends BaseRestController {
    @Resource
    private AccountServiceImpl accountService;

    /**
     * 付款
     */
    @PreAuthorize("isAnonymous()")
    @PostMapping("/payment")
    public R payment(@RequestBody PaymentReqDto paymentReq) {
        accountService.payment(paymentReq);
        return R.ok();
    }

    /**
     * 收款
     */
    @PreAuthorize("isAnonymous()")
    @PostMapping("/receipt")
    public R receipt(@RequestBody ReceiptReqDto receiptReq) {
        accountService.receipt(receiptReq);
        return R.ok();
    }

    /**
     * 获取账户信息
     */
    @PreAuthorize("isAnonymous()")
    @GetMapping("/{account}")
    public R<AccountEntity> get(@PathVariable String account) {
        AccountEntity accountInfo = accountService.get(account);
        return R.ok(accountInfo);
    }
}
